//
//  MHRootLeftViewController.m
//  ManHua
//
//  Created by 赵永泉 on 15/10/24.
//  Copyright © 2015年 蓝欧科技. All rights reserved.
//

#import "MHRootLeftViewController.h"
#import "MHMyselfHeaderView.h"
#import "MHBaseViewController.h"
#import "MHRootLeftCell.h"
#import "MHLoginViewController.h"

@interface MHRootLeftViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) MHBaseViewController *baseVC; //

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) MHMyselfHeaderView *headerView; // 表头View

@property (nonatomic, strong) NSArray *titleArr; // 标题数组
@property (nonatomic, strong) NSArray *iconArr; // 图标数组

@property (nonatomic, strong) NSArray *classArray; // 存放控制器名的数组

@end

@implementation MHRootLeftViewController



- (NSArray *)classArray
{
    if (!_classArray) {
        _classArray = @[@"MHMyReadVC",@"MHMyCollectionVC",@"MHMyCacheVC",@"MHComputerUploadVC"];
    }
    return _classArray;
}


- (void)viewDidLoad {
    [super viewDidLoad];

    UIImageView *bgImg = [[UIImageView alloc]initWithFrame:self.view.bounds];
    bgImg.image = [UIImage imageNamed:@"IMG_1281.jpg"];
    [self.view addSubview:bgImg];
    
    _titleArr = @[@"最近阅读",@"我的收藏",@"我的缓存",@"电脑上传"];
    _iconArr = @[@"iconfont-shijian",@"iconfont-xing",@"iconfont-xiazai (1)",@"iconfont-xiazai"];
    _headerView = [[MHMyselfHeaderView alloc]initWithFrame:CGRectMake(0, 20, Width* 0.66, 140)];
    _headerView.backgroundColor = [UIColor clearColor];
    
    
    _tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _tableView.backgroundColor = [UIColor clearColor];
     _tableView.tableHeaderView = _headerView;
    
    UIView *footerView = [[UIView alloc]init];
    _tableView.tableFooterView = footerView;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; //去掉分隔线
    _tableView.dataSource = self;
    _tableView.delegate = self;
    [_tableView registerClass:[MHRootLeftCell class] forCellReuseIdentifier:@"cell"];
    
    _tableView.rowHeight = 60;
    
    [self.view addSubview:_tableView];
    
    
    [self.headerView.loginBtn addTarget:self action:@selector(didGotoLoginViewController) forControlEvents:UIControlEventTouchUpInside];
    
}


// 前往loginview
- (void)didGotoLoginViewController
{
    MHLoginViewController *loginVC = [[MHLoginViewController alloc]init];
    UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:loginVC];
    [self presentViewController:navi animated:YES completion:^{} ];
}





- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MHRootLeftCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.contentView.backgroundColor = [UIColor clearColor];
    cell.backgroundColor = [UIColor clearColor];
    cell.titleLabel.text = self.titleArr[indexPath.row];
    cell.iconView.image = [UIImage imageNamed:self.iconArr[indexPath.row]];
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     
    _baseVC = [[NSClassFromString(self.classArray[indexPath.row]) alloc]init];
    self.rootLeftBlock(_baseVC);

}



@end
